package com.broad.commerce.code.services.base;

import com.broad.commerce.code.modules.business.InterfaceModule;
import com.broad.commerce.code.modules.jdbc.MybatisModule;
import com.broad.commerce.common.utils.core.StringUtils;

/**
 * The type Interface service.
 * @author stephen
 * @version V1.0
 * @date 2022 -02-08 19:36
 * @description: InterfaceService
 */
public class BaseInterfaceService {
	/***
	 * @author stephen
	 * @date 2022-02-08 19:56
	 * @description: createClassStartTag 接口类通用代码段
	 * @version V1.0
	 **/
	public static void createClassStartTag(StringBuilder sb, InterfaceModule interfaceModule) {
		sb.append("public interface ").append(interfaceModule.getClassName()).append(" {\n");
	}

	/***
	 * @author stephen
	 * @date 2022-02-08 19:53
	 * @description: createClassContent 接口类增删改查通用代码段
	 * @version V1.0
	 **/
	public static void createClassContent(StringBuilder sb, InterfaceModule interfaceModule) {
		String entityName = interfaceModule.getEntityClassName();
		String modelName = interfaceModule.getModelClassName();
		String entityInstance = StringUtils.lowerFirst(entityName);
		String modelInstance = StringUtils.lowerFirst(modelName);
		//查询所有@off
		sb.append("\t").append("/**").append("\n")
		  .append("\t").append("* Select all list").append(".\n")
		  .append("\t").append("* @return the list").append("\n")
		  .append("\t").append("*/").append("\n")
		  .append("\t").append("List<").append(entityName).append("> selectAll();").append("\n")
		  .append("\n");
		// 查询单个
		sb.append("\t").append("/**").append("\n")
		  .append("\t").append("* Find one ").append(entityName).append(".\n")
		  .append("\t").append("* @param id the id").append("\n")
		  .append("\t").append("* @return the ").append(entityName).append("\n")
		  .append("\t").append("*/").append("\n")
		  .append("\t").append(entityName).append(" findOne(Long id);").append("\n")
		  .append("\n");
		//插入单个数据
		sb.append("\t").append("/**").append("\n")
		  .append("\t").append("* Save int.").append("\n")
		  .append("\t").append("* @param ").append(modelInstance).append(" the ").append(modelInstance).append(".\n")
		  .append("\t").append("* @return the ").append(entityInstance).append("\n")
		  .append("\t").append("*/").append("\n")
		  .append("\t").append(entityName).append(" save(").append(modelName).append(" ").append(modelInstance).append(");\n")
		  .append("\n");
		//批量插入数据
		sb.append("\t").append("/**").append("\n")
		  .append("\t").append("* Save all list.").append("\n")
		  .append("\t").append("* @param ").append(modelInstance).append("S the ").append(modelInstance).append("S.\n")
		  .append("\t").append("*/").append("\n")
		  .append("\t").append("void saveAll(List<").append(modelName).append("> ").append(modelInstance).append("S);\n")
		  .append("\n");
		//删除单个数据
		sb.append("\t").append("/**").append("\n")
		  .append("\t").append("* Delete.").append("\n")
		  .append("\t").append("* @param id the id").append("\n")
		  .append("\t").append("*/").append("\n")
		  .append("\t").append("void delete(Long id);").append("\n")
		  .append("\n");//@on
	}

	public static void createClassContent(StringBuilder sb, MybatisModule mybatisModule) {
		//@off 查询所有
		sb.append("\t").append("/**").append("\n")
		  .append("\t").append("* Select all list").append(".\n")
		  .append("\t").append("* @return the list").append("\n")
		  .append("\t").append("*/").append("\n")
		  .append("\t").append("List<").append(mybatisModule.getEntityClassName()).append("> selectAll();").append("\n")
		  .append("\n"); //@on
	}
}
